package com.heima.controller;


import com.heima.pojo.dto.TbSkuDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbSkuVo;
import com.heima.service.ITbSkuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-06
 */
@RestController
@RequestMapping("/api/vm-service/sku")
@RequiredArgsConstructor
public class TbSkuController {
    private final ITbSkuService tbSkuService;

    /**
     * 商品搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param skuName
     * @param classId
     * @return
     */
    @GetMapping("/search")
    private PageResponse<TbSkuVo> selectTbSkuPage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "skuName", required = false) String skuName,
                                                  @RequestParam(value = "classId", required = false) String classId) {
        return tbSkuService.selectTbSkuPage(pageIndex, pageSize, skuName, classId);
    }

    /**
     * 新增商品
     *
     * @param dto
     */
    @PostMapping
    private void insertTbSku(@RequestBody TbSkuDto dto) {
        tbSkuService.insertTbSku(dto);
    }

    /**
     * 修改商品
     * @param skuId
     * @param dto
     */
    @PutMapping("/{skuId}")
    private void updateTbSku(@PathVariable String skuId,
                             @RequestBody TbSkuDto dto) {
        tbSkuService.updateTbSku(skuId, dto);
    }
}
